// 游记添加页面
import axios from 'axios';
import { default as request } from '../request/request';
import { BaseUrl } from '../config'; // 导入BaseUrl

// 创建上传请求实例（用于文件上传，配置不同）
const uploadInstance = axios.create({
  baseURL: BaseUrl, // 使用BaseUrl作为基础URL
  timeout: 30000,
  maxContentLength: 50 * 1024 * 1024,
  maxBodyLength: 50 * 1024 * 1024,
  headers: {
    'Accept': 'application/json'
  }
});

// 添加景区评价
export const addScenicComment = (data) => {
  return request({
    url: '/Introcom/add',
    method: 'post',
    data: data
  });
};

// 游记添加
export const addTravelExperience = (data) => {
  return request({
    url: '/Traexp/add',
    method: 'post',
    data: data
  });
};

// 文件上传
export const uploadFile = (file, id) => {
  const formData = new FormData();
  formData.append('file', file);
  
  return uploadInstance({
    url: '/File/file',
    method: 'post',
    data: formData,
    headers: {
      'id': id
    }
  }).then(response => {
    return `${BaseUrl}/${response.url}`;
  });
};